package com.pos.app.activity.login.presenter;

import com.pos.app.POSApplication;
import com.pos.app.R;
import com.pos.app.activity.login.interactor.LoginInteractor;
import com.pos.app.activity.login.view.ILoginFinishedListener;
import com.pos.app.activity.login.view.ILoginView;
import com.pos.app.comm.Constant;
import com.pos.app.model.LoginConfig;
import com.pos.app.util.ioc.IocContainer;


/**
 * 主导器类
 * @author Administrator
 *
 */
public class LoginPresenterImpl implements LoginPresenter, ILoginFinishedListener
{

	private ILoginView loginView;
	
	private LoginInteractor loginInteractor;

	public LoginPresenterImpl(ILoginView loginView)
	{
		this.loginView = loginView;
		loginInteractor = IocContainer.getShare().get(LoginInteractor.class);
	}

	@Override
	public void onUsernameError()
	{
		//loginView.setUsernameError();
		loginView.hideProgress();
	}

	@Override
	public void onPasswordError()
	{
		//loginView.setPasswordError();
		loginView.hideProgress();
	}

	@Override
	public void onSuccess(int result)
	{
		loginView.hideProgress();
		
		switch (result)
		{
		case Constant.LOGIN_SECCESS: // 登录成功
			loginView.navigateToHome(result);
			break;
		case Constant.LOGIN_ERROR_ACCOUNT_PASS:// 账户或者密码错误
			//loginView.showMessage(POSApplication.getInstance().getResourceMessage(R.string.message_invalid_username_password));
			break;
		case Constant.SERVER_UNAVAILABLE:// 服务器连接失败
			//loginView.showMessage(POSApplication.getInstance().getResourceMessage(R.string.message_server_unavailable));
			break;
		case Constant.LOGIN_ERROR:// 未知异常
			//loginView.showMessage(POSApplication.getInstance().getResourceMessage(R.string.unrecoverable_error));
			break;
		}
	}

	@Override
	public void validateCredentials(LoginConfig loginConfig)
	{
		loginView.showProgress();
		loginInteractor.login(loginConfig, this);
	}

}
